<?php

namespace App\V3\V3_2_6\Models;

use DateTimeInterface;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class AdminPermissionLimitModel extends Model
{


    use HasFactory;

    protected $table = 'admin_permission_limit';
    protected $dateFormat = 'U';//这个时间字段被为被格式化为UNIX 时间戳的形式存储

    public static function getUserPermissionLimit($userId)
    {
        return self::query()->where('user_id', $userId)->first();
    }

    //获取子账号一级模块
    public static function getUserFirstModuleInfo($id): array
    {
        return self::query()->where([
            'upper_module_id' => 0,
            'user_id' => $id
        ])->get()->toArray();
    }

    //获取子账号二级模块
    public static function getUserSecondModuleInfo($id): array
    {
        return self::query()->where([
            'user_id' => $id
        ])
            ->where('upper_module_id', '!=', 0)
            ->get()->toArray();
    }

    //获取用户就得权限
    public static function getUserOldPermissions(array $adminData)
    {
        return self::query()->where('user_id', $adminData['id'])
            ->first();
    }

    protected function serializeDate(DateTimeInterface $date): string
    {
        return $date->format('Y-m-d H:i:s');
    }
}
